package com.junbao.module.main.db

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.junbao.module.main.R
import com.junbao.module.main.databinding.ActivityDataBindingBinding
import com.junbao.module.main.kt.ToastUtils

/**
 *    author : Majunbao
 *    github : https://github.com/MaJunBaox
 *    time   : 2022/8/28 2:21 下午
 *    desc   : Databinding使用
 */
class DataBindingActivity : AppCompatActivity() {

    var loginBean : LoginBean? =null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val binding = DataBindingUtil.setContentView<ActivityDataBindingBinding>(
            this,
            R.layout.activity_data_binding
        )

        loginBean = LoginBean("majunbao", "123456")

        binding.loginBean = loginBean


        binding.editUsername.addTextChangedListener(object :TextWatcher{
            override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {

            }

            override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
                loginBean?.username = p0.toString()
                binding.loginBean = loginBean
            }

            override fun afterTextChanged(p0: Editable?) {
            }

        })
    }

    fun onClick(view : View){
        ToastUtils.show(this , "点击了")
    }
}